package cn.wx.scholar.core.service.importNeo4j;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.neo4j.driver.v1.AuthTokens;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Session;
import org.springframework.stereotype.Service;

@Service
public class PaperFieldRelation {
	
	public static void main(String[] args) {
		writeNeo4j();
	}
	
	public static void writeNeo4j() {
		
		Driver driver = GraphDatabase.driver("bolt://39.105.19.0:7687", AuthTokens.basic("neo4j", "zhongyi!@#2018"));
		Session session = driver.session();
		
		//new日期对象
		Date date = new Date();
		//转换提日期输出格式
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println("开始时间："+dateFormat.format(date));
		
		try {
			
			for(int i=0;i<490;i++) {
				
				String sql = "load csv with headers from 'file:///paperFieldRelation/paperFieldR_"+ i 
						+ ".csv' as line match(f:field{fId:toInt(line.fosId)}) ,(e:paper{fId:toInt(line.paperId)})"
						+ " merge(f)-[r:containsp]->(e) return r";
				
				session.run(sql);
				System.out.println("paperFieldR_" + i +"执行完成");
			}
			
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
			driver.close();
			date = new Date();
			dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			System.out.println("结束时间："+dateFormat.format(date));
		}
	}
}
